package com.njtoyo.taxi.admin.config.oss;

import com.amazonaws.ClientConfiguration;
import com.amazonaws.Protocol;
import com.amazonaws.auth.PropertiesCredentials;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.S3ClientOptions;

public class OOSConfig {

    //OOS_ACCESS_ID
    public static final String OOS_ACCESS_ID = "77d3b7e1b6d9b5e44bb6";

    //OOS_ACCESS_KEY
    public static final String OOS_ACCESS_KEY = "23dc9341d53fcdd8819069fc5c89bf44abe8b3fa";

    //OOS_ENDPOINT
    public static final String OOS_ENDPOINT = "oos-sdqd.ctyunapi.cn";

    //OOS_ENDPOINT_MANAGEMENT
    public static final String OOS_ENDPOINT_MANAGEMENT = "https://oos-cn-mg.ctyunapi.cn";

    //OOS_ENDPOINT_TRAIL
    public static final String OOS_ENDPOINT_TRAIL = "https://oos-cn-cloudtrail.ctyunapi.cn";

    //OOS_ENDPOINT_ACCESS
    public static final String OOS_ENDPOINT_ACCESS = "https://oos-cn-iam.ctyunapi.cn";

    public static AmazonS3 getClientFromConfig(){
        ClientConfiguration clientConfig = new ClientConfiguration();
        //设置连接的超时时间，单位毫秒
        clientConfig.setConnectionTimeout(30*1000);
        //设置 socket 超时时间，单位毫秒
        clientConfig.setSocketTimeout(30*1000) ;
        clientConfig.setProtocol(Protocol.HTTP); //设置 http
        //设置 V4 签名算法中负载是否参与签名，关于签名部分请参看《OOS 开发者文档》
        S3ClientOptions options = new S3ClientOptions();
        options.setPayloadSigningEnabled(true);
        // 创建 client
        AmazonS3 oosClient = new AmazonS3Client(
                new PropertiesCredentials(OOS_ACCESS_ID,
                        OOS_ACCESS_KEY),clientConfig);
        // 设置 endpoint
        oosClient.setEndpoint(OOS_ENDPOINT);
        //设置选项
        oosClient.setS3ClientOptions(options);
        return oosClient;
    }

}
